package 刷题10月.位运算;
// https://leetcode-cn.com/problems/single-number-iii/
public class sz260只出现一次的数字III1030 {
    class Solution {
        public int[] singleNumber(int[] nums) {
            int sum = 0;
            for (int i : nums) sum ^= i;
            int k = -1;
            for (int i = 31; i >= 0 && k == -1; i--) {
                if (((sum >> i) & 1) == 1) k = i;
            }
            int[] ans = new int[2];
            for (int i : nums) {
                if (((i >> k) & 1) == 1) ans[1] ^= i;
                else ans[0] ^= i;
            }
            return ans;
        }
    }

}
